﻿package com.evidencer.java.net;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

public class UDPReceiveDemo {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {			
		// 建立监听用套接字
		DatagramSocket ds=new DatagramSocket(10000);
		// 初始化接收用缓冲区
		byte[] bytes=new byte[1024];
		// 将缓冲区封装到数据包
		DatagramPacket dp=new DatagramPacket(bytes,bytes.length);
		// 接收数据包
		ds.receive(dp);
		// 打印接收信息
		System.out.println(dp.getAddress().getHostAddress()+"receive："+new String(dp.getData()));
		// 关闭UDP连接
		ds.close();
	

	}

}
